//==============================================================================
#include "App.h"
#include "Client.h"
#include <iostream>

//==============================================================================
CApp::CApp() {
    Surf_Display = NULL;
    Running = true;
}

//------------------------------------------------------------------------------
int CApp::OnExecute() {

    if(OnInit() == false) {
        return -1;
    }

    SDL_Event Event;
    

	while(Running) {
        while(SDL_PollEvent(&Event)) {
            OnEvent(&Event);
        }

		OnLoop();
		OnRender();
    }

    OnCleanup();

    return 0;
}

//==============================================================================
int main(int argc, char* argv[]) {
    CApp* theApp = new CApp();

	CClient& client = CClient::getInstance();

    return theApp->OnExecute();
}

//==============================================================================

void CApp::addPlayer()
{

	CPlayer* player =        new CPlayer();
	player->OnLoad("./images/characters/ff.png", 22, 31, 3);
	player->X = 300*(CEntity::PlayerList.size()+1);
	player->Y = 300;
	player->castTime = 10;
	CEntity::PlayerList.push_back(player);
	
}

bool CApp::removePlayer(int ID)
{
	if(ID < 0 || ID > CEntity::PlayerList.size()-1)
	{
		return false;
	}
	else
	{
		CEntity::PlayerList.erase(CEntity::PlayerList.begin()+ID);
		return true;
	}
}